program mpi_hello
    ! 导入MPI库所需的模块
    use mpi
    implicit none

    integer :: ierr, rank, size

    ! 1. 初始化 MPI 环境
    call MPI_INIT(ierr)

    ! 2. 获取进程总数 (size)
    call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierr)

    ! 3. 获取当前进程排名 (rank)
    call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)

    ! 4. 打印消息
    print *, "Hello from process ", rank, " of ", size, " total processes."

    ! 5. 结束 MPI 环境
    call MPI_FINALIZE(ierr)

end program mpi_hello